package com.carl.condition;

import com.carl.annotation.ConditionalOnSystem;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

@Configuration
public class OnSystemCondition implements Condition {

    private String  systemDefault = "linux"; // Mac linux

    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        Map<String, Object> attrs = annotatedTypeMetadata.getAnnotationAttributes(ConditionalOnSystem.class.getName());
        String systemValue = attrs.get("system").toString();
        System.out.print("# sys : " + systemValue + "\n\n");
        boolean flag = systemDefault.equals(systemValue);
        return flag;
    }
}
